<template>

    <div id="fnTimeCountDown" class="fnTimeCountDown" style="margin:0">
      <span class="hour">{{int_hour}}</span>
      <font>时</font>
      <span class="mini">{{int_minute}}</span>
      <font>分</font>
      <span class="sec">{{int_second}}</span>
      <font>秒</font>
      <span class="hm">{{int_millisecond}}</span>
    </div>

</template>

<script>
  import HomemScroll from "../HomemScroll";
  import {mapGetters,mapMutations} from "vuex";
  export default {
    props: {
      overTime: {
        type: Number,
        default: () => {
          return (new Date()).getTime() + 3000
        }
      }
    },
    data() {
      return {
        int_day: " ",
        int_hour: " ",
        int_minute: " ",
        int_second: " ",
        int_millisecond: "",
      }
    },
    components: {
      HomemScroll
    },
    methods: {

      /*--------------------------------------------------------------------------*/
      fnTimeCountDown() {
        setTimeout(this.show_time, 1000);
      },

      show_time() {
        var time_now, time_end, time_distance, timerID;
        /*var int_day, int_hour, int_minute, int_second;*/
        time_now = new Date();
        time_now = time_now.getTime();
        time_end = new Date(this.overTime);
        time_end = time_end.getTime();
        time_distance = time_end - time_now;
        if(time_distance > 0) {
          this.int_day = Math.floor(time_distance / 86400000)
          time_distance -= this.int_day * 86400000;
          this.int_hour = Math.floor(time_distance / 3600000)
          time_distance -= this.int_hour * 3600000;
          this.int_minute = Math.floor(time_distance / 60000)
          time_distance -= this.int_minute * 60000;
          this.int_second = Math.floor(time_distance / 1000)
          time_distance -= this.int_second * 1000;
          this.int_millisecond = Math.floor(time_distance / 100)
          if(this.int_hour < 10)
            this.int_hour = "0" + this.int_hour;
          if(this.int_minute < 10)
            this.int_minute = "0" + this.int_minute;
          if(this.int_second < 10)
            this.int_second = "0" + this.int_second;

          timerID = setTimeout(this.show_time, 1);
        } else {
          clearTimeout(timerID)
//
//          this.$emit('timeOver')
        }
      },

    },
    created() {
      this.fnTimeCountDown()

    },
    mounted() {

    }
  }
</script>

<style>

</style>
